<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/25 0025
 * Time: 9:19
 */
namespace app\adminapi\controller;

use app\adminapi\model\Api;
use app\api\model\JWT;
use think\App;
use think\Controller;
use think\helper\Hash;
use think\Db;

/**
 * @title 离职交接
 * @description 接口说明
 * @header name:flag require:1 default: desc:手机设备号
 */
class Resign extends Api
{
    /**
     * @title 选择员工
     * @description 接口说明
     * @author 开发者
     * @url /adminapi/Resign/staff
     * @method POST  
     * 
     *  @return user:用户@
     * @user id:id username:姓名 avatar:头像 mobiles:手机 
     * 
     */
    public function staff()
    {
        $user = $this->user;
        $users = db::name('user')->where('hid',$user['hid'])->field('id,username,mobiles,avatar,position')->select();
        foreach ($users as $k => $v) {
            if($v['avatar']){
                $users[$k]['avatar'] = get_file_path($v['avatar']);
            }
        }
        $list['user'] = $users;
        if($users){
            return $this->ajaxReturn(0,'成功',$list);
        }
    }
    /**
     * @title 确认交接
     * @description 接口说明
     * @author 开发者
     * @url /adminapi/resign/resign
     * @method POST  
     * @param name:ids type:int require:1 default: other: desc:被交接人
     * @param name:id type:int require:1 default: other: desc:交接人
     */
    public function resign()
    {
        $user = $this->user;
        // 交出方
        $id = input('id');
        // 接收方
        $ids = input('ids');
        if(!$ids || !$id){
            return $this->ajaxReturn(1,'缺少参数');
        }
        // $datas['manager_id'] = $ids;
        $data['manager'] = db::name('user')->where('id',$ids)->value('username');
        



        db::name('client')->where('manager_id',$id)->update(['manager_id'=>$ids,'manager'=>$data['manager']]);
        db::name('client_zero')->where('manager_id',$id)->update(['manager_id'=>$ids,'manager'=>$data['manager']]);


        db::name('scheduled')->where('director_id',$id)
        ->where('type','neq',3)
        ->update(['director_id'=>$ids,'director'=>$data['manager']]);
        db::name('zero')->where('director_id',$id)
        ->where('status','lt',3)
        ->update(['director_id'=>$ids,'director'=>$data['manager']]);

            return $this->ajaxReturn(0,'成功');
        


    }

}